package c.e.b.h.e.l;

import android.util.Log;
import c.e.b.h.e.b;
import c.e.b.h.e.k.g;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Locale;

/* compiled from: QueueFileLogStore */
public class e implements a {
    public static final Charset d = Charset.forName("UTF-8");
    public final File a;
    public final int b;
    public c c;

    /* compiled from: QueueFileLogStore */
    public class a {
        public final byte[] a;
        public final int b;

        public a(e eVar, byte[] bArr, int i) {
            this.a = bArr;
            this.b = i;
        }
    }

    public e(File file, int i) {
        this.a = file;
        this.b = i;
    }

    public void a() {
        g.c(this.c, "There was a problem closing the Crashlytics log file.");
        this.c = null;
    }

    public String b() {
        byte[] c = c();
        return c != null ? new String(c, d) : null;
    }

    /* JADX WARNING: Removed duplicated region for block: B:15:0x0045  */
    /* JADX WARNING: Removed duplicated region for block: B:14:0x0044 A:{RETURN} */
    public byte[] c() {
        /*
        r7 = this;
        r0 = r7.a;
        r0 = r0.exists();
        r1 = 0;
        r2 = 0;
        if (r0 != 0) goto L_0x000c;
    L_0x000a:
        r4 = r1;
        goto L_0x0042;
    L_0x000c:
        r7.f();
        r0 = r7.c;
        if (r0 != 0) goto L_0x0014;
    L_0x0013:
        goto L_0x000a;
    L_0x0014:
        r3 = 1;
        r3 = new int[r3];
        r3[r2] = r2;
        r0 = r0.s0();
        r0 = new byte[r0];
        r4 = r7.c;	 Catch:{ IOException -> 0x002a }
        r5 = new c.e.b.h.e.l.d;	 Catch:{ IOException -> 0x002a }
        r5.m6102init(r7, r0, r3);	 Catch:{ IOException -> 0x002a }
        r4.q(r5);	 Catch:{ IOException -> 0x002a }
        goto L_0x003b;
    L_0x002a:
        r4 = move-exception;
        r5 = c.e.b.h.e.b.a;
        r6 = 6;
        r5 = r5.a(r6);
        if (r5 == 0) goto L_0x003b;
    L_0x0034:
        r5 = "FirebaseCrashlytics";
        r6 = "A problem occurred while reading the Crashlytics log file.";
        android.util.Log.e(r5, r6, r4);
    L_0x003b:
        r4 = new c.e.b.h.e.l.e$a;
        r3 = r3[r2];
        r4.m1766init(r7, r0, r3);
    L_0x0042:
        if (r4 != 0) goto L_0x0045;
    L_0x0044:
        return r1;
    L_0x0045:
        r0 = r4.b;
        r1 = new byte[r0];
        r3 = r4.a;
        java.lang.System.arraycopy(r3, r2, r1, r2, r0);
        return r1;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.e.b.h.e.l.e.c():byte[]");
    }

    public void d() {
        g.c(this.c, "There was a problem closing the Crashlytics log file.");
        this.c = null;
        this.a.delete();
    }

    public void e(long j, String str) {
        f();
        String str2 = " ";
        if (this.c != null) {
            if (str == null) {
                str = "null";
            }
            try {
                int i = this.b / 4;
                if (str.length() > i) {
                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.append("...");
                    stringBuilder.append(str.substring(str.length() - i));
                    str = stringBuilder.toString();
                }
                str = str.replaceAll("\r", str2).replaceAll("\n", str2);
                this.c.k(String.format(Locale.US, "%d %s%n", new Object[]{Long.valueOf(j), str}).getBytes(d));
                while (!this.c.r() && this.c.s0() > this.b) {
                    this.c.v();
                }
            } catch (IOException e) {
                if (b.a.a(6)) {
                    Log.e("FirebaseCrashlytics", "There was a problem writing to the Crashlytics log.", e);
                }
            }
        }
    }

    public final void f() {
        if (this.c == null) {
            try {
                this.c = new c(this.a);
            } catch (IOException e) {
                b bVar = b.a;
                StringBuilder g = c.b.a.a.a.g("Could not open log file: ");
                g.append(this.a);
                bVar.e(g.toString(), e);
            }
        }
    }
}
